#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>

int prime(int n)
{
	for (int i = 2; i < sqrt(n); i++)
	{
		if (n % i == 0)
		{
			return 0;
		}
	}
	return 1;
}

int hw(int n) {
	int arr[5] = { 0 };
	int j = 0;
	while (n > 0)
	{
		arr[j++] = n % 10;
		n = n / 10;
	}
	int left = 0;
	int right = 4;
	while (left <= right)
	{
		if (arr[left] != arr[right])
		{
			return 0;
		}
		left++;
		right--;
	}
	return 1;
}

int main() {
	int i = 0;
	for (i = 10000; i < 100000; i++)
	{
		if (hw(i) && prime(i))
		{
			printf("%d ", i);
		}
	}
	return 0;
}